from wormbane.ui.selection_dialog import selection_dialog

def command_remove(game, ui):
    removable = [item for item in game.hero.inv if item.is_armor and item.worn]
    if not removable:
        game.write(game.hero, 'has nothing to remove')
        return

    if len(removable) == 1:
        selection = set(removable)
    else:
        selection = selection_dialog(ui.stdscr, removable, prompt = 'Remove')
        if not selection:
            game.write('Never mind.')
            return

    for item in selection:
        if item.beatitude == 'cursed':
            item.beatitude_id = True
            game.write(game.hero, 'cannot remove', item)
        else:
            game.hero.remove(item)
            game.write(game.hero, 'removes', item)
            item.merge()
            game.hero_moved = True
